package magicArt.activity;

import magicArt.view.MagicSymbolView;
import src.margicArt.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;

public class BattleActivity extends Activity {

	/** 怪物血量 */
	private int monHP = 100;
	private ProgressBar monsterHP;
	/** 发动魔法按钮 */
	Button useMagic;
	/** 散去元素按钮 */
	Button clearElement;
	/** 施放魔法区域 */
	MagicSymbolView magicSymbolView;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.battle);

		// 设定怪物血量
		monsterHP = (ProgressBar) findViewById(R.id.monsterHP);
		monsterHP.setProgress(monHP);
		// 绑定"发动魔法"按钮的侦听事件
		useMagic = (Button) findViewById(R.id.useMagic);
		useMagic.setOnClickListener(new UseMagicLintener());
		// 绑定“散去元素”按钮的侦听事件
		clearElement = (Button) findViewById(R.id.clearElement);
		clearElement.setOnClickListener(new ClearElementLintener());
		magicSymbolView = (MagicSymbolView) findViewById(R.id.magicSymbol);
	}

	/**
	 * 
	 * “散去元素”按钮的侦听事件
	 * 
	 */
	class ClearElementLintener implements OnClickListener {

		/**
		 * “散去元素”按钮按下
		 * 
		 * @param v
		 *            当前操作视图
		 */
		public void onClick(View v) {
			// 魔法散去
			magicSymbolView.clear();
		}
	}

	/**
	 * "发动魔法"按钮的侦听事件
	 * 
	 */
	class UseMagicLintener implements OnClickListener {

		/**
		 * "发动魔法"按钮按下
		 * 
		 * @param v
		 *            当前操作视图
		 */
		@Override
		public void onClick(View v) {
			monHP -= 10;
			if (monHP < 0) {
				monHP = 0;
			}
			monsterHP.setProgress(monHP);
			// 魔法散去
			magicSymbolView.clear();
		}
	}
}
